<?php
	$ls_gridname	= 'dtl_pelatihan';


// ----------------- >> Form Detail << ----------------- ?>
<script type="text/javascript">
	var controllerPelatihan = 'hrd_pelatihan_karyawan';
    var idKaryawan = $('#id_karyawan_pk').val();

    var f_status_pelatihan = function(val) {
    	var pesan =  '';
    	if (val == 1) {
    		pesan = 'Sertifikat';
    	} else if(val == 0) {
    		pesan = 'Tanpa Sertifikat';
    	} 
    	else {
    		pesan = '';
    	}

    	return pesan;
    }

	$(document).ready(function(){
		// Setup Form
		$('#form_<?php echo $ls_gridname; ?>').setupForm([
			{ name: 'id_pelatihan_pk', type:'text', size:'medium' },
			{ name: 'nama_pelatihan', type:'text', size:'medium', noempty:true },
			{ name: 'tahun_pelatihan', type: 'text', maxlength:'4' },
			{ name: 'penyelenggara_pelatihan', type: 'text' },
			{ name: 'status_sertifikat', type: 'text', size:'medium', data:[{'value':'','display':''}, {'value':'0','display':'Tanpa Sertifikat'}, {'value':'1','display':'Sertifikat'}] },
			{ name: 'ket_pelatihan', type: 'text', size:'long' }
		], {}, { prefix:'<?php echo $ls_gridname; ?>_' });
		
		// Set Hidden Object
		$('#<?php echo $ls_gridname; ?>_id_pelatihan_pk').hide();
		
		// Create Dialog
		$('#form_<?php echo $ls_gridname; ?>_container').dialog({
			closed:true,
			modal:true,
			title: '_',
			width:550,
			height: 400,
			buttons:[{
				text:'Save',
				iconCls:'icon-save',
				handler:function(){
					$('#form_<?php echo $ls_gridname; ?>').submitForm('/'+controllerPelatihan+'/ajax_post/'+idKaryawan, { onComplete : function(){ $('#form_<?php echo $ls_gridname; ?>_container').dialog('close'); 
						$('#<?php echo $ls_gridname; ?>').datagrid('reload'); }} );
				}
			},{
				text:'Close',
				iconCls:'icon-cancel',
				handler:function(){
					$('#form_<?php echo $ls_gridname; ?>_container').dialog('close');
				}
			}]
		});

	});
</script>
<div id="form_<?php echo $ls_gridname; ?>_container" style="padding:5px;width:600px;height:400px;">
	<div id="form_<?php echo $ls_gridname; ?>">
    <table class="tb_form" style="width:100%;" cellpadding="0" cellspacing="0">
    <tr>
        <td class="label">Nama Pelatihan</td>
        <td><input id="nama_pelatihan" /><input id="id_pelatihan_pk" /></td>
    </tr>
    <tr>
        <td class="label">Penyelenggara Pelatihan</td>
        <td><input id="penyelenggara_pelatihan" /></td>
    </tr>
    <tr>
        <td class="label">Tahun <span style="font-size:10px; font-style:italic;">(1990)</span></td>
        <td><input id="tahun_pelatihan" /></td>
    </tr>
    <tr>
        <td class="label">Status Sertifikat</td>
        <td><input id="status_sertifikat" /></td>
    </tr>
    <tr>
        <td class="label">Keterangan</td>
        <td><input id="ket_pelatihan" /></td>
    </tr>
    </table>
	</div>
</div>
<?php 

// ----------------- >> Table Detail << ----------------- ?>
<script type="text/javascript">
	$(document).ready(function(){
		$('#<?php echo $ls_gridname; ?>').datagrid({
			url:gs_path+'/'+controllerPelatihan+'/getdata/'+idKaryawan,
			columns:[[
				{ field : 'nama_pelatihan', title : 'Nama Pelatihan', width : 150 },
				{ field : 'penyelenggara_pelatihan', title : 'Penyelenggara', width : 100 },
				{ field : 'tahun_pelatihan', title : 'Tahun', width : 100 },
				{ field : 'status_sertifikat', title : 'Status Sertifikat', width : 150, formatter:f_status_pelatihan },
				{ field : 'ket_pelatihan', title : 'Keterangan', width : 250 }

			]],
			<?php if($mode!='view'){ 
			// -->> Toolbar [Start]
			// Only Appear On Mode Create / Edit ?>
			toolbar:[{
				text:'Tambah',
				iconCls:'icon-add',
				handler:function(){
					resetError();
					$('#<?php echo $ls_gridname; ?>_id_pelatihan_pk').readonly();
					$('#form_<?php echo $ls_gridname; ?>_container').dialog('open');
					$('#form_<?php echo $ls_gridname; ?>').data('mode', 'create');
					$('#form_<?php echo $ls_gridname; ?>_container').prev().find('.panel-title').html('Tambah Data');
					
					$('#form_<?php echo $ls_gridname; ?>').resetForm();
					$('#form_<?php echo $ls_gridname; ?>').focusFirst();
				}
			},'-',{
				text:'Ubah',
				iconCls:'icon-edit',
				handler:function(){
					var oSel=$('#<?php echo $ls_gridname; ?>').datagrid('getSelected'); 
					if(oSel==null){ alert('Please select row!'); }
					else{ 
						resetError();
						$('#<?php echo $ls_gridname; ?>_id_pelatihan_pk').readonly();
						$('#form_<?php echo $ls_gridname; ?>_container').dialog('open');
						$('#form_<?php echo $ls_gridname; ?>').data('mode', 'edit');
						$('#form_<?php echo $ls_gridname; ?>_container').prev().find('.panel-title').html('Ubah Data');
						
						jsonToForm(oSel, {prefix:'<?php echo $ls_gridname; ?>_'});
						$('#form_<?php echo $ls_gridname; ?>').focusFirst();
					}
				}
			},'-',{
				text:'Hapus',
				iconCls:'icon-remove',
				handler:function() {
					var oSel = $('#<?php echo $ls_gridname; ?>').datagrid('getSelected'); 
                    if (oSel == null) { 
                        $.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
                    } else { 
                        var url = gs_path+'/'+controllerPelatihan+'/ajax_delete?id_pelatihan_pk='+oSel.id_pelatihan_pk;
                        // Confirm Hapus
						$.messager.confirm('Confirm', 'yakin menghapus data ini?', function(r){
			                if (r){
			                    $.get( url, function(  ) {
								  	$('#<?php echo $ls_gridname; ?>').datagrid('reload');
								});
			                }
			            });
                    } 

				}
			}],<?php 
			} // -->> Toolbar [End]
			?>
			onClickRow:function(rowIndex){
				var lastIndex = $('#<?php echo $ls_gridname; ?>').data('selectedIndex');
				$('#<?php echo $ls_gridname; ?>').data('selectedIndex', rowIndex);
			},
			onLoadSuccess:function(){ }
		});
	});
	
</script>
<table id="<?php echo $ls_gridname; ?>" style="width:600;height:auto" singleSelect="true" idField="index_no" showFooter="true">
<thead>
    <tr>
    	<th field="id_pelatihan_pk" hidden="true"></th>
        <!-- <th field="nama_pelatihan" width="150" >Nama Pelatihan</th>
        <th field="penyelenggara_pelatihan" width="100" >Penyelenggara Pelatihan</th>
        <th field="tahun_pelatihan" width="100" >Tahun</th>
        <th field="status_sertifikat" width="150" >Status</th>
        <th field="ket_pelatihan" width="250" >Keterangan</th> -->
    </tr>
</thead>
</table>
